<?php
// 后台网址管理模块
class LinksAction extends CommonAction {


	public function _before_add(){

		$Cat = M('Cat');
		$rs = $Cat->where('status=1')->field('id,cat_name')->order('cat_order DESC,id ASC')->select();
		$this->assign('cat_list', $rs );

	}

	public function _before_insert(){

        // 检测用户名是否冲突
        $name  =  $_REQUEST['site_link'];
		
		/*
		if(!preg_match('/^[a-z]\w{4,}$/i',$name)) {
            $this->error( '网址格式错误！'.$name);
        }*/
		$Links = M('Links');
        $result  =  $Links->getBySite_link($name);
        if($result) {
        	$this->error('该网站地址已经存在！');
        }
			
		$_POST['ctime'] = time();//创建时间
		$_POST['site_pwd'] = md5($_REQUEST['site_pwd']);
		
	}

	public function _before_edit(){
		$Cat = M('Cat');
		$rs = $Cat->where('status=1')->field('id,cat_name')->order('cat_order DESC,id ASC')->select();
		$this->assign('cat_list', $rs );

	}

	public function _before_update(){
        // 检测用户名是否冲突
        $name  =  $_REQUEST['site_link'];
		$id	   =  $_REQUEST['id'];
		$Links = M('Links');
        $result  =  $Links->getBySite_link($name);
        if($result && $result['id'] != $id ) {
        	$this->error('该网站地址已经存在！');
        }
		$_POST['password'] = md5($_REQUEST['password']);

	}
 


}
?>